/**
 * Created by hao.cheng on 2017/4/28.
 */
import { RouteItem } from '../routers/Type';

/**
 * 校验是否登录
 * @param permits
 */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const checkLogin = (permits: any): boolean =>
    (process.env.NODE_ENV === 'production' && !!permits) || process.env.NODE_ENV === 'development';

/**
 * @description 递归查询对应的路由
 * @param {String} path 当前访问地址
 * @param {Array} routes 路由列表
 * @returns array
 */
export const searchRoute = (path: string, routes: RouteItem[] = []): RouteItem => {
    let result: RouteItem = {};
    for (const item of routes) {
        if (item.path === path) return item;
        if (item.children) {
            const res = searchRoute(path, item.children);
            if (Object.keys(res).length) result = res;
        }
    }
    return result;
};
